/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client.anim;

import java.awt.*;

/**
 *
 * @author Kristopher T Babic
 */
public class CirclePath extends AnimationPath {

    static private final int _defaultRadius = 1;
    static private final double _defaultDeltaAngle = Math.toRadians(1.0);

    private double deltaAngle;
    private int x_radius;
    private int y_radius;

    public CirclePath() {
        super();
        init(_defaultDeltaAngle, _defaultRadius);
    }

    public CirclePath(Point origin) {
        super(origin);
        init(_defaultDeltaAngle, _defaultRadius);
    }

    public CirclePath(Point origin, int radius) {
        super(origin);
        init(_defaultDeltaAngle, _defaultRadius);
    }

    public CirclePath(Point origin, int radius, double angle) {
        super(origin);
        init(angle, radius);
    }

    private void init(double angle, int radius) {
        setRadius(radius);
        setDeltaAngle(angle);
    }

    public void setDeltaAngle(double angle) {
        this.deltaAngle = Math.toRadians(angle);
    }

    public double getDeltaAngle() {
        return Math.toDegrees(this.deltaAngle);
    }

    // might want to add both features as public???
    private double getDeltaAngleRadians() {
        return this.deltaAngle;
    }

    public void setXRadius(int radius) {
        this.x_radius = radius;
    }

    public void setYRadius(int radius) {
        this.y_radius = radius;
    }

    public int getXRadius() {
        return this.x_radius;
    }

    public int getYRadius() {
        return this.y_radius;
    }

    public void setRadius(int radius) {
        setRadius(radius, radius);
    }

    public void setRadius(int x_rad, int y_rad) {
        setXRadius(x_rad);
        setYRadius(y_rad);
    }
//  public int getRadius () { return this.radius; }

    public String toString() {
        return "Circle Path -\nRadius: " + getXRadius() + " x " + getYRadius() + "\nDelta Angle: " + getDeltaAngle();
    }

    public Point getLocation() {
        long cycles = getCycles();
        double angle = getDeltaAngleRadians() * (double) cycles;
//System.out.print(angle+" ");

        Point loc = getStartLocation();

        int x = (int) (((double) getXRadius()) * Math.sin(angle) + (double) loc.x);
        int y = (int) (((double) getYRadius()) * Math.cos(angle) + (double) loc.y);

        Point location = null;

        return getReflectedLocation(x, y);

    }

    public void setLocation(Point loc) {
        setStartLocation(loc);
        setStartTime();
// i could use this logic to create some more realistic moves.  maybe later....
//  loc.x = x - r sin (a)
//  loc.y = y - r cos (a)
    }

}
